<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>净值统计</title>
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <script src="../layui/layui.js"></script>
    <script src="../code/code/highcharts.js"></script>
    <script src="../code/modules/data.js"></script>
    <style>::-webkit-scrollbar{display: none;}</style>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
</head>
<body>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
<script language="JavaScript">
    var dats=new Date();
    var tt=[];
    var xs="";
    $.ajax({
        url:"/dy/da",
        method:"get",
        success:function (msg) {
            for(var j=0;j<366;j++){
                var dat=new Date((dats.getTime()-j*60*60*24*1000));
                if(dat.getDay()!=0&&dat.getDay()!=6){
                    for(var i=0;i<msg.length;i++){
                        var qaz=new Date(Date.parse(msg[i].holidaydate));
                        var sjsx=qaz.getTime()+(60*60*1000*24)*(msg[i].days-1);
                        if(dat.getTime()<=(qaz.getTime()-60*60*24*1000)||dat.getTime()>=sjsx){
                            var sj=dat.getFullYear()+"-"+(dat.getMonth()+1)+"-"+dat.getDate();
                            tt.unshift(sj);
                            //xs+="'"+dat.getDate()+"-"+(dat.getMonth()+1)+"月-"+dat.getFullYear()+"',";
                            xs+="to_char(to_date('"+dat.getFullYear()+"-"+(dat.getMonth()+1)+"-"+dat.getDate()+"','yyyy-MM-dd'),'yyyy-MM-dd'),";//"'"+dat.getFullYear()+"-"+(dat.getMonth()+1)+"-"+dat.getDate()+"'";
                            break;
                        }
                    }
                }

                if(tt.length>=7){
                    break;
                }
            }
            var mm=xs.substring(0,xs.length-1);
            $.ajax({
                url: "/WorthStatisticsController/xxs/" + mm,
                method: "post",
                success:  function (msg) {
                    var xsx=[];


                    $(document).ready(function() {
                        var chart = {
                            type: 'column'
                        };
                                             var title = {
                            text: '2021年净值总览-显示七天数据'
                        };
                        var subtitle = {
                            text: 'Source: runoob.com'
                        };
                        var xAxis = {
                            categories: msg.sj,
                            crosshair: true
                        };

                        var yAxis = {
                            min: 0,
                            title: {
                                text: '元'
                            }
                        };
                        var tooltip = {
                            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                                '<td style="padding:0"><b>{point.y:.1f}元</b></td></tr>',
                            footerFormat: '</table>',
                            shared: true,
                            useHTML: true
                        };
                        var plotOptions = {
                            column: {
                                pointPadding: 0.01,
                                borderWidth: 0
                            }
                        };
                        var credits = {
                            enabled: false
                        };

                        var series= msg.suj;

                        var json = {};
                        json.chart = chart;
                        json.width=400;
                        json.height=600;
                        json.title = title;
                        json.subtitle = subtitle;
                        json.tooltip = tooltip;
                        json.xAxis = xAxis;
                        json.yAxis = yAxis;
                        json.series = series;
                        json.plotOptions = plotOptions;
                        json.credits = credits;
                        $('#container').highcharts(json);

                    });
                }

            });
        }
    })

</script>
<blockquote class="layui-elem-quote news_search">
    <script type="text/html" id="secStock_search">
        <!--多条件查询层-->
        <div style="float: left;display: none">
            <form class="layui-form layui-col-md12 x-so">
                <!--查询日期：-->
                <div class="layui-input-inline">
                    <input type="date" name="date" id="date" placeholder="请输入统计日期" autocomplete="off" class="layui-input"/>
                </div>
                <button id="search" class="layui-btn layui-btn-sm layui-btn-danger" lay-submit data-type="reload" lay-filter="provinceSearch">
                    <i class="layui-icon">&#xe615;</i>
                </button>
            </form>
        </div>
        <!--多条件查询结束-->

        <!--头部工具栏-->
        <div class="layui-btn-container layui-input-inline" style="margin-left: 1000px;">
            <button class="layui-btn layui-btn-normal" lay-event="getCheckData" style="width: 100px;">统计</button>
            <button class="layui-btn layui-btn-normal layui-btn-danger"  style="width: 130px;" lay-event="batchDel">
                <i class="layui-icon">&#xe640;</i>批量删除
            </button>
        </div>
    </script>
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script>
        layui.use('table', function () {
            var table = layui.table;

            table.render({
                elem: '#test'
                , url: '../WorthStatisticsController/method'
                ,height:"740px"
                , toolbar: '#secStock_search' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , title: '用户数据表'
                , cols: [[ //表头
                    {checkbox:true},//开启多选框
                    {field: 'netDate', title: '净值统计日期', sort: true,templet:function (d) {
                            return layui.util.toDateString(d.netDate,'yyyy-MM-dd')
                        }}
                    , {field: 'totalAssets', title: '总资产(元)',templet:function (d) {
                            if (d.totalAssets.toString().indexOf(".")!=-1){
                                return d.totalAssets.toLocaleString();
                            }else{
                                return (d.totalAssets+ '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,')+".00";
                            }
                        }}
                    , {field: 'totalRespo', title: '总负债(元)', sort: true,templet:function (d) {
                            if (d.totalRespo.toString().indexOf(".")!=-1){
                                return d.totalRespo.toLocaleString();
                            }else{
                                return (d.totalRespo+ '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,')+".00";
                            }
                        }}
                    /*, {field: 'share', title: '总份额'}*/
                    , {field: 'netAsset', title: '资产净值(元)',templet:function (d) {
                            if (d.netAsset.toString().indexOf(".")!=-1){
                                return d.netAsset.toLocaleString();
                            }else{
                                return (d.netAsset+ '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,')+".00";
                            }
                        }},
                    {field: 'assetValue', title: '单位净值(元)',templet:function (d) {
                            if (d.assetValue.toString().indexOf(".")==-1){
                                return d.assetValue.toLocaleString()+".0000000000";
                            }else{
                                return d.assetValue.toFixed(10);
                            }
                        }}
                ]]
                , page: true
                ,limit:15
                ,limits: [5, 10,20,30,50]
                ,parseData:function (res) {
                    var arr=res.shareNumber;
                    var datas=res.data;
                    if (arr!=null && arr.length!=0 && datas!=null && datas.length!=0){
                        for (let i = 0; i <datas.length ; i++) {
                            datas[i].share=arr;
                        }
                    }
                    return {
                        "code": res.code,
                        "msg": res.msg,
                        "count": res.count,
                        "data": datas
                    }
                }
            });


            Date.prototype.format = function(fmt) {
                var o = {
                    "M+" : this.getMonth()+1,                 //月份
                    "d+" : this.getDate(),                    //日
                    "h+" : this.getHours(),                   //小时
                    "m+" : this.getMinutes(),                 //分
                    "s+" : this.getSeconds(),                 //秒
                    "q+" : Math.floor((this.getMonth()+3)/3), //季度
                    "S"  : this.getMilliseconds()             //毫秒
                };
                if(/(y+)/.test(fmt)) {
                    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
                }
                for(var k in o) {
                    if(new RegExp("("+ k +")").test(fmt)){
                        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
                    }
                }
                return fmt;
            }

            //绑定表格头部事件
            table.on("toolbar(test)",function (obj) {
                //检查表格选择操作状态
                var checkStatus = table.checkStatus(obj.config.id);
                switch(obj.event){
                    case "getCheckData":
                        $.ajax({
                            url:"../WorthStatisticsController/total",
                            type:"post",
                            data:"",
                            success:function (data) {
                                if (data=="success") layer.msg("统计成功",{icon:1});
                                else if (data=="fail") layer.msg("统计失败",{icon:2});
                                else if (data=="already") layer.msg("当天已统计",{icon:2});
                                else layer.msg(data);
                                table.reload("test");
                            }
                        });
                        break;
                    //批量删除操作：删除选定的多行数据
                    case "batchDel":
                        //获得选中的表格行
                        var data = checkStatus.data;
                        //判断是否大于0行
                        if(data.length>0){
                            layer.confirm('请确认是否真的删除?', function(index){
                                //获取所有选择的id
                                var dataIdStr="";
                                for (var i = 0; i < data.length; i++) {
                                    var date=new Date(data[i].netDate);
                                    dataIdStr = dataIdStr+date.format("yyyy-MM-dd").toString().substring(0,10)+",";//累加字符
                                }
                                //去掉最后多余逗号
                                dataIdStr=dataIdStr.substring(0,dataIdStr.length-1);
                                layer.close(index);
                                //使用ajax删除选中的
                                $.ajax({
                                    type: "delete",//提交方式为put,替代delte请求
                                    url: "/WorthStatisticsController/method/"+dataIdStr,//后台Servlet路径
                                    success: function(msg){
                                        layer.msg('删除成功');
                                        //重新加载表格数据
                                        table.reload('test');
                                    }
                                });
                            });
                        }else{
                            //没有选择数据行
                            layer.msg('你至少选一行！');
                        }
                        break;
                }
            })

        });
    </script>
</blockquote>
</body>
</html>